"use strict";

module.exports = {
  up: (queryInterface, Sequelize) => {
    return queryInterface.createTable("product_specs", {
      id: {
        allowNull: false,
        autoIncrement: true,
        primaryKey: true,
        type: Sequelize.INTEGER,
      },
      product_id: {
        type: Sequelize.INTEGER,
        allowNull: false,
        comment: "商品ID",
      },
      spec_name: {
        type: Sequelize.STRING(50),
        allowNull: false,
        comment: "规格名称(如:颜色,尺寸)",
      },
      spec_value: {
        type: Sequelize.STRING(100),
        allowNull: false,
        comment: "规格值(如:红色,XL)",
      },
      price: {
        type: Sequelize.DECIMAL(10, 2),
        comment: "该规格价格(为空则使用商品默认价格)",
      },
      cost_price: {
        type: Sequelize.DECIMAL(10, 2),
        comment: "该规格成本价",
      },
      stock: {
        type: Sequelize.INTEGER,
        allowNull: false,
        defaultValue: 0,
        comment: "该规格库存",
      },
      image: {
        type: Sequelize.STRING(255),
        comment: "该规格图片",
      },
      sku: {
        type: Sequelize.STRING(50),
        comment: "SKU编码",
      },
      sort_order: {
        type: Sequelize.INTEGER,
        allowNull: false,
        defaultValue: 0,
        comment: "排序",
      },
      created_at: {
        allowNull: false,
        type: Sequelize.DATE,
      },
      updated_at: {
        allowNull: false,
        type: Sequelize.DATE,
      },
    });
  },
  down: (queryInterface, Sequelize) => {
    return queryInterface.dropTable("product_specs");
  },
};
